<?php
/* wwwschool project

Copyright (C) 2009  Phillip Aldridge
Email : info@imi21.com
Web site http://www.imi21.com

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/


/**
 *  File : listCoursesStudent.php
 *  called only via ajax 
 *  List all the lessons for the course which this student is allowed to do
 *  @ 
 */  
 

checkSession();

require '../../includes/classes/WS3tableview.php';
require '../../includes/classes/WS3user.php';
require '../../includes/classes/WS3course.php';

$user = new WS3_User(); 
if ($user->setUserID( $session->userID() ) )
{  

  $course=new WS3_Course();
  $course->setCourseID( $_POST['id'] );

 
  $db=new WS3_Database();

//  

 $q="SELECT l2c.id AS l2cid, l2c.position AS l2cposition,
  l2c.lesson_id AS l2clesson_id,
  l.name AS lname, l.id AS lid
  FROM 
  `lesson2course` AS l2c
  RIGHT JOIN `lesson` AS l ON l.id=l2c.lesson_id
  RIGHT JOIN `course` AS c ON c.id=l2c.course_id
  WHERE l2c.course_id = '".$course->CourseID()."'
  AND l.active = '1'
  AND c.active = '1'
  ORDER BY l2c.position
  "; // 

  
  if ($db->query($q))
  {
  
  $table=new WS3_TableView('main',400);
  $table->setTitle( 'Listing lessons in '.$course->CourseName().' for '.$user->FullName() );
  $table->addColumnTH('Position');
  $table->addColumnTH('Name');
  $table->addColumn('Modules','listStudentModules');
  $table->setAlternativeRows(true);
  $table->setInfoRow(true);
    
  
    $count = $db->numberRows();
    while ( $db->nextRecord() )
    {
       $table->addRow($db->f('lid'), array(
          'Position'=>$db->f('l2cposition'),
         'Name' => javaSafeString( $db->f('lname') )
        ));
  
    } 
    $table->addToInfoRow("<p>Count = $count </p>");
     echo $table->display();
    $message="Listing";
   
  }else{
    $message="Error : Empty list";
  }


}
/** Get menu */
require '../../includes/menus/topGoContent.php';
$menu=javaSafeString($menu);
echo "document.getElementById('topmenu').innerHTML='$menu';";

echo "document.getElementById('messages').innerHTML='$message';";
if (W3DEBUG)  $debug=new WS3_Debug();

?>
